package com.freelancer.musicinstruction.tasks;

import com.freelancer.musicinstruction.activity.interfaces.Loadable;

public abstract class LoadableTask<T extends Loadable> implements Runnable {
	
	public static final String TAG = LoadableTask.class.getSimpleName();
	
	
	protected T activity;
	
	public LoadableTask( T activity ){
		this.activity = activity;
	}

	@Override
	public void run() {
		
		boolean interrupt = false;
		activity.onLoadingStarting();
		
		try{
			doActualTask();
		}
		catch( Exception e ){
			interrupt = true;
			activity.onLoadingInterrupted();
		}
		finally {
			if( !interrupt ){
				activity.onLoadingComplete();
			}
		}
		
	}
	
	public abstract void doActualTask();
}
